package com.yequan.work;

import java.text.*;
import java.util.*;

/**
 * @author yequan
 * @date 2021/03/09 17:49
 **/
public class TimeScop {

    /**
     * 小于出发时间前 30 分钟
     */
    private final static int BEFORE_SUB_30MINUTE = 1;
    /**
     * 大于等于出发时间前 30 分钟，小于出发时间
     */
    private final static int BETWEEN_START_SUB_30MINUTE = 2;
    /**
     * 大于等于出发时间，小于等于出发时间后 10 分钟
     */
    private final static int BETWEEN_START_ADD_10MINUTE = 3;
    /**
     * 大于出发时间后 10 分钟
     */
    private final static int AFTER_ADD_10MINUTE = 4;

    private static int getTimeScope(Date planStartTime) throws Exception {
        long planStartTimeMills = planStartTime.getTime();
        long now = System.currentTimeMillis();
        long before30Minute = DateUtil.addDateMinut(planStartTime, -30).getTime();
        System.out.println(DateUtil.date2String(DateUtil.addDateMinut(planStartTime, -30)));
        long after10Minute = DateUtil.addDateMinut(planStartTime, 10).getTime();
//        if (now < planStartTimeMills) {
//            //当前时间未到出发时间
//            if (now < before30Minute) {
//                //出发前 30 分钟
//                return BEFORE_SUB_30MINUTE;
//            } else {
//                //出发时间前 30 分钟 ----  出发时间
//                return BETWEEN_START_SUB_30MINUTE;
//            }
//        } else {
//            //当前时间已到出发时间
//            if (now <= after10Minute){
//                return BETWEEN_START_ADD_10MINUTE;
//            } else {
//                return AFTER_ADD_10MINUTE;
//            }
//        }
        if (now < before30Minute) {
            //小于出发时间前 30 分钟
            return BEFORE_SUB_30MINUTE;
        } else if (now < planStartTimeMills) {
            //大于等于出发时间前 30 分钟，小于出发时间
            return BETWEEN_START_SUB_30MINUTE;
        } else if (now <= after10Minute) {
            //大于等于出发时间，小于等于出发时间后 10 分钟
            return BETWEEN_START_ADD_10MINUTE;
        } else {
            //大于出发时间后 10 分钟
            return AFTER_ADD_10MINUTE;
        }
    }

    public static void main(String[] args) throws Exception {
        System.out.println(getTimeScope(DateUtil.string2Date("20210309185000")));

    }

}
